﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TeamOPSchoolCup.Domain.POCO;
using TeamOPSchoolCup.Domain.DAL;
using TeamOPSchoolCup.Domain.Services;

namespace TeamOPSchoolCup.Web.Controllers
{
  public class SportController : Controller
  {
    //
    // GET: /Sport/

    public ViewResult Index()
    {
      return View(SportService.GetSports(true));
    }

    //
    // GET: /Sport/Details/5

    public ViewResult Details(int id)
    {
      Sport sport = SportService.GetSport(id);
      return View(sport);
    }

    //
    // GET: /Sport/Create

    public ActionResult Create()
    {
      return View();
    }

    //
    // POST: /Sport/Create

    [HttpPost]
    public ActionResult Create(Sport sport)
    {
      if (ModelState.IsValid)
      {
        SportService.AddSport(sport);
        return RedirectToAction("Index");
      }

      return View(sport);
    }

    //
    // GET: /Sport/Edit/5

    public ActionResult Edit(int id)
    {
      Sport sport = SportService.GetSport(id);
      return View(sport);
    }

    //
    // POST: /Sport/Edit/5

    [HttpPost]
    public ActionResult Edit(Sport sport)
    {
      if (ModelState.IsValid)
      {
        SportService.UpdateSport(sport);
        return RedirectToAction("Index");
      }
      return View(sport);
    }
  }
}